package com.flurry.android;

import android.text.TextUtils;
import com.flurry.android.caching.CachingManager;
import com.flurry.android.caching.ObjectData;
import com.flurry.android.caching.ObjectOperationData;
import com.flurry.android.responses.AppCloudApplyOperationResonseHandler;
import com.flurry.android.responses.AppCloudCommonOperationResponseHandler;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

abstract class cx
  implements AppCloudObserver
{
  protected String mCollectionName = "";
  protected String mEmail;
  protected String mId = "";
  protected String mUsername;
  protected HashMap<String, String> paramMap = new HashMap();
  protected String password;

  public boolean containsObserver()
  {
    return r.d(this.mId);
  }

  protected void createObject(JSONObject paramJSONObject)
  {
    while (true)
    {
      try
      {
        if (paramJSONObject.has("_type"))
          this.mCollectionName = paramJSONObject.getString("_type");
        if (!paramJSONObject.has("_id"))
          break label111;
        this.mId = paramJSONObject.getString("_id");
        break label111;
        if (i < paramJSONObject.length())
        {
          String str1 = paramJSONObject.names().getString(i);
          String str2 = paramJSONObject.getString(str1);
          if ((!str1.equals("code")) || (!str1.equals("note")))
            this.paramMap.put(str1, str2);
          i++;
          continue;
        }
      }
      catch (JSONException localJSONException)
      {
        localJSONException.printStackTrace();
      }
      return;
      label111: int i = 0;
    }
  }

  protected void createUser(JSONObject paramJSONObject)
  {
    while (true)
    {
      try
      {
        if (paramJSONObject.has("username"))
          this.mUsername = paramJSONObject.getString("username");
        if (paramJSONObject.has("email"))
          this.mEmail = paramJSONObject.getString("email");
        if (!paramJSONObject.has("_id"))
          break label110;
        this.mId = paramJSONObject.getString("_id");
        break label110;
        if (i < paramJSONObject.length())
        {
          String str1 = paramJSONObject.names().getString(i);
          String str2 = paramJSONObject.getString(str1);
          this.paramMap.put(str1, str2);
          i++;
          continue;
        }
      }
      catch (JSONException localJSONException)
      {
        localJSONException.printStackTrace();
      }
      return;
      label110: int i = 0;
    }
  }

  protected void decrement(String paramString1, String paramString2, AppCloudCommonOperationResponseHandler paramAppCloudCommonOperationResponseHandler)
  {
    if ((this instanceof AppCloudUser));
    for (ObjectOperationData localObjectOperationData = new ObjectOperationData(this.mId); ; localObjectOperationData = new ObjectOperationData(this.mId, this.mCollectionName))
    {
      localObjectOperationData.addKeyValue(paramString1, paramString2);
      FlurryAppCloud.C().decrementOperation(localObjectOperationData, new fv(this, paramAppCloudCommonOperationResponseHandler));
      return;
    }
  }

  protected void delete(AppCloudResponseHandler paramAppCloudResponseHandler)
  {
    boolean bool = this instanceof AppCloudUser;
    if (bool);
    for (ObjectData localObjectData = new ObjectData(this.mId); ; localObjectData = new ObjectData(this.mId, this.mCollectionName))
    {
      FlurryAppCloud.E().c(localObjectData, new gb(this, bool, paramAppCloudResponseHandler));
      return;
    }
  }

  public String get(String paramString)
  {
    try
    {
      if (this.paramMap.containsKey(paramString))
      {
        String str = (String)this.paramMap.get(paramString);
        return str;
      }
      return null;
    }
    catch (Exception localException)
    {
    }
    return null;
  }

  public float getFloat(String paramString)
  {
    try
    {
      if (this.paramMap.containsKey(paramString))
      {
        float f = Float.parseFloat((String)this.paramMap.get(paramString));
        return f;
      }
      return 0.0F;
    }
    catch (Exception localException)
    {
    }
    return 0.0F;
  }

  public String getId()
  {
    return this.mId;
  }

  public int getInt(String paramString)
  {
    try
    {
      if (this.paramMap.containsKey(paramString))
      {
        int i = Integer.parseInt((String)this.paramMap.get(paramString));
        return i;
      }
      return 0;
    }
    catch (Exception localException)
    {
    }
    return 0;
  }

  public Vector<NameValuePair> getKeyValues()
  {
    Vector localVector = new Vector();
    Iterator localIterator = this.paramMap.entrySet().iterator();
    while (localIterator.hasNext())
    {
      Map.Entry localEntry = (Map.Entry)localIterator.next();
      String str = (String)localEntry.getKey();
      if ((!str.startsWith("_")) && (!str.equals("username")) && (!str.equals("email")) && (!str.equals("code")) && (!str.equals("note")))
        localVector.add(new BasicNameValuePair(str, (String)localEntry.getValue()));
    }
    return localVector;
  }

  protected void getObjectOrUser(AppCloudResponseHandler paramAppCloudResponseHandler)
  {
    boolean bool = this instanceof AppCloudUser;
    ObjectData localObjectData;
    if (bool)
      localObjectData = new ObjectData(this.mId);
    try
    {
      while (true)
      {
        FlurryAppCloud.E().d(localObjectData, new fy(this, paramAppCloudResponseHandler, bool));
        return;
        localObjectData = new ObjectData(this.mId, this.mCollectionName);
      }
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
    }
  }

  protected void increment(String paramString1, String paramString2, AppCloudCommonOperationResponseHandler paramAppCloudCommonOperationResponseHandler)
  {
    if ((this instanceof AppCloudUser));
    for (ObjectOperationData localObjectOperationData = new ObjectOperationData(this.mId); ; localObjectOperationData = new ObjectOperationData(this.mId, this.mCollectionName))
    {
      localObjectOperationData.addKeyValue(paramString1, paramString2);
      FlurryAppCloud.C().incrementOperation(localObjectOperationData, new ga(this, paramAppCloudCommonOperationResponseHandler));
      return;
    }
  }

  public boolean isAutoSyncEnabled()
  {
    return r.e(this.mId);
  }

  final void q(String paramString)
  {
    if (FlurryAppCloud.D().getPendingData().x(paramString));
    for (ObjectData localObjectData1 = FlurryAppCloud.D().getPendingData().getObjectById(paramString); ; localObjectData1 = null)
    {
      if (FlurryAppCloud.D().getServerData().x(paramString));
      for (ObjectData localObjectData2 = FlurryAppCloud.D().getServerData().getObjectById(paramString); ; localObjectData2 = null)
      {
        if ((localObjectData1 == null) && (localObjectData2 == null));
        while (true)
        {
          return;
          String str = null;
          if (localObjectData2 != null)
            str = localObjectData2.getCollectionName();
          if ((TextUtils.isEmpty(str)) && (localObjectData1 != null))
            localObjectData1.getCollectionName();
          setId(paramString);
          if (localObjectData2 != null)
            for (int j = 0; j < localObjectData2.getKeyValues().size(); j++)
              set(((NameValuePair)localObjectData2.getKeyValues().get(j)).getName(), ((NameValuePair)localObjectData2.getKeyValues().get(j)).getValue());
          int i = 0;
          if (localObjectData1 != null)
            while (i < localObjectData1.getKeyValues().size())
            {
              set(((NameValuePair)localObjectData1.getKeyValues().get(i)).getName(), ((NameValuePair)localObjectData1.getKeyValues().get(i)).getValue());
              i++;
            }
        }
      }
    }
  }

  public boolean removeAllObservers()
  {
    if (TextUtils.isEmpty(this.mId))
      return false;
    return r.a(this.mId);
  }

  public boolean removeObserver(AppCloudValueUpdateHandler paramAppCloudValueUpdateHandler)
  {
    if (TextUtils.isEmpty(this.mId))
      return false;
    return r.a(this.mId, paramAppCloudValueUpdateHandler);
  }

  public boolean removeObserverForKey(String paramString)
  {
    if (TextUtils.isEmpty(this.mId))
      return false;
    return r.a(this.mId, paramString);
  }

  public void saveOrCreateWithCompletionHandler(AppCloudApplyOperationResonseHandler paramAppCloudApplyOperationResonseHandler)
    throws Exception
  {
    boolean bool = this instanceof AppCloudUser;
    ObjectData localObjectData;
    if (bool)
    {
      localObjectData = new ObjectData(this.mId);
      localObjectData.setKeyValues(getKeyValues());
      if ((this.mUsername != null) && (!this.mUsername.equals("")))
        localObjectData.addKeyValue("username", this.mUsername);
      if ((this.password != null) && (!this.password.equals("")))
        localObjectData.addKeyValue("password", this.password);
      if ((this.mEmail != null) && (!this.mEmail.equals("")))
        localObjectData.addKeyValue("email", this.mEmail);
    }
    while (TextUtils.isEmpty(this.mId))
    {
      if (bool)
      {
        ObjectOperationData localObjectOperationData = new ObjectOperationData(null);
        Vector localVector = localObjectData.getKeyValues();
        int i = 0;
        while (true)
          if (i < localVector.size())
          {
            localObjectOperationData.addKeyValue(((NameValuePair)localVector.get(i)).getName(), ((NameValuePair)localVector.get(i)).getValue());
            i++;
            continue;
            localObjectData = new ObjectData(this.mId, this.mCollectionName);
            localObjectData.setKeyValues(getKeyValues());
            break;
          }
        FlurryAppCloud.C().saveOrCreateOperation(localObjectOperationData, new ge(this, paramAppCloudApplyOperationResonseHandler));
        return;
      }
      FlurryAppCloud.E().a(localObjectData, new gd(this, paramAppCloudApplyOperationResonseHandler));
      return;
    }
    FlurryAppCloud.E().b(localObjectData, new fz(paramAppCloudApplyOperationResonseHandler));
  }

  public void saveToCache()
  {
    for (int i = 0; i < getKeyValues().size(); i++)
    {
      String str1 = ((NameValuePair)getKeyValues().get(i)).getName();
      String str2 = ((NameValuePair)getKeyValues().get(i)).getValue();
      FlurryAppCloud.D().getServerData().b(str1, str2, this.mId, this.mCollectionName);
    }
  }

  public void set(String paramString, Object paramObject)
  {
    if ((paramString.equals("code")) || (paramString.equals("note")))
      return;
    if (this.paramMap.containsKey(paramString))
    {
      this.paramMap.remove(paramString);
      this.paramMap.put(paramString, paramObject.toString());
      return;
    }
    this.paramMap.put(paramString, paramObject.toString());
  }

  public boolean setAutoSyncEnabled(boolean paramBoolean)
  {
    if (paramBoolean)
      return r.b(this.mId);
    return r.c(this.mId);
  }

  protected void setId(String paramString)
  {
    this.mId = paramString;
  }

  public String toString()
  {
    String str1 = "" + "id : " + this.mId + " ; ";
    Vector localVector = getKeyValues();
    Object localObject = str1;
    int i = 0;
    while (i < localVector.size())
    {
      String str2 = (String)localObject + "\n( key : value ) = ( " + ((NameValuePair)localVector.get(i)).getName() + " : " + ((NameValuePair)localVector.get(i)).getValue() + " )";
      i++;
      localObject = str2;
    }
    return localObject;
  }
}

/* Location:           E:\android\Toy Defense 2_dex2jar.jar
 * Qualified Name:     com.flurry.android.cx
 * JD-Core Version:    0.6.2
 */